/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.paroquiadegloria.ejc.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author jadson
 */
public class ConnectionFactory {

    public static Connection con;
    private static final String PROPERTIES_FILE = "datasource";

    public static Connection getConnection() {
        ConfigProperties properties = new ConfigProperties(PROPERTIES_FILE);
        try {
            if (con == null || con.isClosed()) {
                Class.forName(properties.getValue("DRIVER"));
                con = DriverManager.getConnection(properties.getValue("URL"), 
                        properties.getValue("USER"), properties.getValue("PASS"));
            }
        } catch (SQLException e) {
            System.out.println("Não foi possível estabelecer a conexão: " + e.getMessage());
        } catch (ClassNotFoundException ex) {
            System.out.println("Erro ao obter Driver de conexão: " + ex.getMessage());
        }
        return con;
    }
}
